const wxpayment = {
  payment_alipay_param (e) {
    window.location.href=e;
  },
  payment_UnionPay_param (e) {
    document.write(e);
    document.pay_form.submit();
  },
  payment_wechatPay_param (e) {
    var isOrder=e.is_order;
    var isPaper=e.is_paper;
    var orderId=e.order_id;
    var isBranch=e.is_branch;
    var price=e.price;
    window.jsApiParameters = e;
    callpay();
    function callpay()
    {
        console.log('callpay-----------');
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall();
        }
    }

    //调用微信JS api 支付
    function jsApiCall()
    {
        console.log('jsApiCall-----------');
        WeixinJSBridge.invoke(
              'getBrandWCPayRequest',
              window.jsApiParameters ,
              function(res){
                  if(res.err_msg.indexOf("ok")!=-1){
                      var str="?isOrder="+isOrder+"&isPaper="+isPaper+"&orderId="+orderId+"&isBranch="+isBranch+"&price="+price;
                      window.location.href ="http://chubanshe.almas.biz/Press_wap/page/unionpay.php"+str;
                      return false;
                  }
                  WeixinJSBridge.log(res.err_msg);
                  alert(res.err_code+res.err_desc+res.err_msg);
                  console.log(res.err_code+res.err_desc+res.err_msg);
                  history.go(-1);
              }
        );
    }
  }
}
 
const meta = {
  wxpayment: 
  [
    {
      name: 'payment_alipay_param',
      args: ['function']
    },
     {
      name: 'payment_UnionPay_param',
      args: ['function']
    },
    {
      name: 'payment_wechatPay_param',
      args: ['function']
    }
  ]
}

export default {
  init (Weex) {
    // 注册这个模块，最后一个参数是模块的元信息.
    Weex.registerApiModule('wxpayment', wxpayment, meta)
  }
}
